{% extends 'generic/object.html' %}
{% load helpers %}
{% load plugins %}
{% load tz %}

{% block breadcrumbs %}
  {{ block.super }}
  <li class="breadcrumb-item">
    <a href="{% url 'dcim:module_list' %}?module_type_id={{ object.module_type.pk }}">{{ object.module_type }}</a>
  </li>
{% endblock %}

{% block extra_controls %}
  {% if perms.dcim.change_module %}
    <div class="dropdown">
      <button id="add-components" type="button" class="btn btn-sm btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
        <i class="mdi mdi-plus-thick" aria-hidden="true"></i> Add Components
      </button>
      <ul class="dropdown-menu" aria-labeled-by="add-components">
        {% if perms.dcim.add_consoleport %}
          <li><a class="dropdown-item" href="{% url 'dcim:consoleport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_consoleports' pk=object.device.pk %}">Console Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_consoleserverport %}
          <li><a class="dropdown-item" href="{% url 'dcim:consoleserverport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_consoleserverports' pk=object.device.pk %}">Console Server Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_powerport %}
          <li><a class="dropdown-item" href="{% url 'dcim:powerport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_powerports' pk=object.device.pk %}">Power Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_poweroutlet %}
          <li><a class="dropdown-item" href="{% url 'dcim:poweroutlet_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_poweroutlets' pk=object.device.pk %}">Power Outlets</a></li>
        {% endif %}
        {% if perms.dcim.add_interface %}
          <li><a class="dropdown-item" href="{% url 'dcim:interface_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_interfaces' pk=object.device.pk %}">Interfaces</a></li>
        {% endif %}
        {% if perms.dcim.add_frontport %}
          <li><a class="dropdown-item" href="{% url 'dcim:frontport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_frontports' pk=object.device.pk %}">Front Ports</a></li>
        {% endif %}
        {% if perms.dcim.add_rearport %}
          <li><a class="dropdown-item" href="{% url 'dcim:rearport_add' %}?device={{ object.device.pk }}&module={{ object.pk }}&return_url={% url 'dcim:device_rearports' pk=object.device.pk %}">Rear Ports</a></li>
        {% endif %}
      </ul>
    </div>
  {% endif %}
{% endblock %}

{% block content %}
<div class="row">
	<div class="col col-md-6">
    <div class="card">
      <h5 class="card-header">Module</h5>
      <div class="card-body">
        <table class="table table-hover attr-table">
          <tr>
            <th scope="row">Device</th>
            <td>{{ object.device|linkify }}</td>
          </tr>
          <tr>
            <th scope="row">Device Type</th>
            <td>{{ object.device.device_type|linkify }}</td>
          </tr>
          <tr>
            <th scope="row">Module Type</th>
            <td>{{ object.module_type|linkify }}</td>
          </tr>
          <tr>
            <th scope="row">Serial Number</th>
            <td class="font-monospace">{{ object.serial|placeholder }}</td>
          </tr>
          <tr>
            <th scope="row">Asset Tag</th>
            <td class="font-monospace">{{ object.asset_tag|placeholder }}</td>
          </tr>
        </table>
      </div>
    </div>
    {% include 'inc/panels/custom_fields.html' %}
    {% include 'inc/panels/tags.html' %}
    {% include 'inc/panels/comments.html' %}
    {% plugin_left_page object %}
    </div>
    <div class="col col-md-6">
      <div class="card">
        <h5 class="card-header">Components</h5>
        <div class="card-body">
          <table class="table table-hover attr-table">
            <tr>
              <th scope="row">Interfaces</th>
              <td>
                {% with component_count=object.interfaces.count %}
                  {% if component_count %}
                    <a href="{% url 'dcim:interface_list' %}?module_id={{ object.pk }}">{{ component_count }}</a>
                  {% else %}
                    {{ ''|placeholder }}
                  {% endif %}
                {% endwith %}
              </td>
            </tr>
            <tr>
              <th scope="row">Console Ports</th>
              <td>
                {% with component_count=object.consoleports.count %}
                  {% if component_count %}
                    <a href="{% url 'dcim:consoleport_list' %}?module_id={{ object.pk }}">{{ component_count }}</a>
                  {% else %}
                    {{ ''|placeholder }}
                  {% endif %}
                {% endwith %}
              </td>
            </tr>
            <tr>
              <th scope="row">Console Server Ports</th>
              <td>
                {% with component_count=object.consoleserverports.count %}
                  {% if component_count %}
                    <a href="{% url 'dcim:consoleserverport_list' %}?module_id={{ object.pk }}">{{ component_count }}</a>
                  {% else %}
                    {{ ''|placeholder }}
                  {% endif %}
                {% endwith %}
              </td>
            </tr>
            <tr>
              <th scope="row">Power Ports</th>
              <td>
                {% with component_count=object.powerports.count %}
                  {% if component_count %}
                    <a href="{% url 'dcim:powerport_list' %}?module_id={{ object.pk }}">{{ component_count }}</a>
                  {% else %}
                    {{ ''|placeholder }}
                  {% endif %}
                {% endwith %}
              </td>
            </tr>
            <tr>
              <th scope="row">Power Outlets</th>
              <td>
                {% with component_count=object.poweroutlets.count %}
                  {% if component_count %}
                    <a href="{% url 'dcim:poweroutlet_list' %}?module_id={{ object.pk }}">{{ component_count }}</a>
                  {% else %}
                    {{ ''|placeholder }}
                  {% endif %}
                {% endwith %}
              </td>
            </tr>
            <tr>
              <th scope="row">Front Ports</th>
              <td>
                {% with component_count=object.frontports.count %}
                  {% if component_count %}
                    <a href="{% url 'dcim:frontport_list' %}?module_id={{ object.pk }}">{{ component_count }}</a>
                  {% else %}
                    {{ ''|placeholder }}
                  {% endif %}
                {% endwith %}
              </td>
            </tr>
            <tr>
              <th scope="row">Rear Ports</th>
              <td>
                {% with component_count=object.rearports.count %}
                  {% if component_count %}
                    <a href="{% url 'dcim:rearport_list' %}?module_id={{ object.pk }}">{{ component_count }}</a>
                  {% else %}
                    {{ ''|placeholder }}
                  {% endif %}
                {% endwith %}
              </td>
            </tr>
          </table>
        </div>
      </div>
      {% plugin_right_page object %}
	</div>
</div>
<div class="row">
  <div class="col col-md-12">
    {% plugin_full_width_page object %}
  </div>
</div>
{% endblock %}
